package com.jueye.onlinetalk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jueye.onlinetalk.entry.Role;
import com.jueye.onlinetalk.entry.UserRoleRel;
import com.jueye.onlinetalk.entry.bo.RoleBo;
import com.jueye.onlinetalk.entry.bo.UserRoleRelBo;
import com.jueye.onlinetalk.entry.vo.RoleVo;
import com.jueye.onlinetalk.service.RoleService;
import com.jueye.onlinetalk.mapper.RoleMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author ASUS
* @description 针对表【role(房间)】的数据库操作Service实现
* @createDate 2025-07-07 10:28:39
*/
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role>
    implements RoleService{

    @Resource
    private RoleMapper roleMapper;

    public QueryWrapper<Role> getQueryWrapper(RoleBo roleBo) {
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        if (roleBo != null) {
            queryWrapper.eq(roleBo.getId() != null, "id", roleBo.getId());
            queryWrapper.like(roleBo.getName() != null, "name", roleBo.getName());
            queryWrapper.in(roleBo.getIds() != null, "id", roleBo.getIds());
        }
        return queryWrapper;
    }

    @Override
    public List<RoleVo> getVos(RoleBo roleBo) {
        List<Role> roles = roleMapper.selectList(getQueryWrapper(roleBo));
        List<RoleVo> roleVos = new ArrayList<>();
        for (Role role : roles) {
            RoleVo roleVo = new RoleVo();
            BeanUtils.copyProperties(role, roleVo);
            roleVos.add(roleVo);
        }
        return roleVos;
    }
}




